<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>28.实现strStr()</title>
	</head>
	<body>
		<script type="text/javascript">
			let haystack = 'aaaabbabcbbccc'
			let needle = 'abc'
			let strStr = function(haystack, needle) {
				// return haystack.indexOf(needle)
				if(needle.length===0) return 0;
				    for(let i = 0; i < haystack.length-needle.length+1;i++){
						if(haystack[i] === needle[0]){
							if(haystack.slice(i,i+needle.length) === needle){
								return i;
							}
						}
					}
				    return -1
			};
			let result = strStr(haystack,needle)
			console.log(result)
		</script>
	</body>
</html>
